<template>
  <div class="page-container">
    <div class="page-header">
      <button class="back-button" @click="goToHome">
        <span class="icon-arrow-left">←</span>
        返回首页
      </button>
      <div class="header-content">
        <h2>假期安排</h2>
        <p>管理员工的请假申请和假期计划</p>
      </div>
    </div>
    
    <div class="card filters-card">
      <div class="filters-container">
        <div class="filter-group">
          <label>假期类型:</label>
          <select v-model="typeFilter" @change="filterVacations">
            <option value="all">全部</option>
            <option value="annual">年假</option>
            <option value="sick">病假</option>
            <option value="personal">事假</option>
            <option value="marriage">婚假</option>
            <option value="maternity">产假</option>
          </select>
        </div>
        <div class="filter-group">
          <label>状态:</label>
          <select v-model="statusFilter" @change="filterVacations">
            <option value="all">全部</option>
            <option value="pending">待审批</option>
            <option value="approved">已批准</option>
            <option value="rejected">已拒绝</option>
          </select>
        </div>
        <div class="filter-actions">
          <button class="btn-primary" @click="showAddVacationModal = true">
            <span class="icon-plus">+</span> 申请假期
          </button>
        </div>
      </div>
    </div>
    
    <div class="card">
      <div class="card-header">
        <h3>假期列表</h3>
        <div class="header-stats">
          <div class="stat-item">
            <span class="stat-label">待审批:</span>
            <span class="stat-value pending-count">{{ pendingCount }}</span>
          </div>
          <div class="stat-item">
            <span class="stat-label">本月假期总数:</span>
            <span class="stat-value">{{ monthlyCount }}</span>
          </div>
        </div>
      </div>
      <div class="card-body">
        <div class="table-responsive">
          <table class="data-table">
            <thead>
              <tr>
                <th>员工姓名</th>
                <th>假期类型</th>
                <th>开始日期</th>
                <th>结束日期</th>
                <th>天数</th>
                <th>状态</th>
                <th>申请理由</th>
                <th>操作</th>
              </tr>
            </thead>
            <tbody>
              <tr v-for="(vacation, index) in filteredVacations" :key="index" class="table-row">
                <td>{{ vacation.employee }}</td>
                <td>
                  <span :class="['vacation-type', vacation.type]">{{ getVacationTypeText(vacation.type) }}</span>
                </td>
                <td>{{ formatDate(vacation.startDate) }}</td>
                <td>{{ formatDate(vacation.endDate) }}</td>
                <td>{{ vacation.days }}</td>
                <td>
                  <span :class="['status', vacation.status]">{{ getStatusText(vacation.status) }}</span>
                </td>
                <td class="reason-cell">{{ vacation.reason }}</td>
                <td class="action-buttons">
                  <template v-if="vacation.status === 'pending'">
                    <button class="btn-action btn-approve" @click="approveVacation(index)">批准</button>
                    <button class="btn-action btn-reject" @click="rejectVacation(index)">拒绝</button>
                  </template>
                  <template v-else>
                    <button class="btn-action" @click="viewVacation(index)">查看</button>
                    <button class="btn-action btn-danger" @click="deleteVacation(index)">删除</button>
                  </template>
                </td>
              </tr>
              <tr v-if="filteredVacations.length === 0">
                <td colspan="8" class="empty-state">
                  <div class="empty-icon">🏖️</div>
                  <p>暂无符合条件的假期申请</p>
                </td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>

    <!-- 假期申请弹窗 -->
    <div v-if="showAddVacationModal" class="modal-backdrop">
      <div class="modal">
        <div class="modal-header">
          <h3>{{ editingIndex !== null ? '编辑假期申请' : '申请假期' }}</h3>
          <button class="modal-close" @click="showAddVacationModal = false">&times;</button>
        </div>
        <div class="modal-body">
          <div class="form-group">
            <label>员工姓名</label>
            <select class="form-control">
              <option>张三</option>
              <option>李四</option>
              <option>王五</option>
              <option>赵六</option>
            </select>
          </div>
          <div class="form-group">
            <label>假期类型</label>
            <select class="form-control">
              <option value="annual">年假</option>
              <option value="sick">病假</option>
              <option value="personal">事假</option>
              <option value="marriage">婚假</option>
              <option value="maternity">产假</option>
            </select>
          </div>
          <div class="form-row">
            <div class="form-group">
              <label>开始日期</label>
              <input type="date" class="form-control">
            </div>
            <div class="form-group">
              <label>结束日期</label>
              <input type="date" class="form-control">
            </div>
          </div>
          <div class="form-group">
            <label>申请理由</label>
            <textarea class="form-control" rows="3" placeholder="请输入申请理由"></textarea>
          </div>
        </div>
        <div class="modal-footer">
          <button class="btn-secondary" @click="showAddVacationModal = false">取消</button>
          <button class="btn-primary" @click="saveVacation">提交申请</button>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: 'VacationArrange',
  data() {
    return {
      vacations: [
        {
          employee: '张三',
          type: 'annual',
          startDate: '2023-10-10',
          endDate: '2023-10-15',
          days: 6,
          status: 'pending',
          reason: '计划外出旅游'
        },
        {
          employee: '李四',
          type: 'sick',
          startDate: '2023-10-03',
          endDate: '2023-10-05',
          days: 3,
          status: 'approved',
          reason: '感冒发烧'
        },
        {
          employee: '王五',
          type: 'personal',
          startDate: '2023-09-28',
          endDate: '2023-09-29',
          days: 2,
          status: 'rejected',
          reason: '家中有事'
        },
        {
          employee: '赵六',
          type: 'marriage',
          startDate: '2023-11-01',
          endDate: '2023-11-10',
          days: 10,
          status: 'pending',
          reason: '结婚'
        }
      ],
      typeFilter: 'all',
      statusFilter: 'all',
      showAddVacationModal: false,
      editingIndex: null
    }
  },
  computed: {
    filteredVacations() {
      return this.vacations.filter(vacation => {
        const typeMatch = this.typeFilter === 'all' || vacation.type === this.typeFilter;
        const statusMatch = this.statusFilter === 'all' || vacation.status === this.statusFilter;
        return typeMatch && statusMatch;
      });
    },
    pendingCount() {
      return this.vacations.filter(vacation => vacation.status === 'pending').length;
    },
    monthlyCount() {
      const now = new Date();
      const month = now.getMonth();
      const year = now.getFullYear();
      return this.vacations.filter(vacation => {
        const date = new Date(vacation.startDate);
        return date.getMonth() === month && date.getFullYear() === year;
      }).length;
    }
  },
  methods: {
    goToHome() {
      this.$router.push('/home');
    },
    filterVacations() {},
    formatDate(dateStr) {
      return new Date(dateStr).toLocaleDateString('zh-CN');
    },
    getVacationTypeText(type) {
      const map = {
        annual: '年假',
        sick: '病假',
        personal: '事假',
        marriage: '婚假',
        maternity: '产假'
      };
      return map[type] || type;
    },
    getStatusText(status) {
      const map = {
        pending: '待审批',
        approved: '已批准',
        rejected: '已拒绝'
      };
      return map[status] || status;
    },
    approveVacation(index) {
      if (confirm('确定要批准这条假期申请吗？')) {
        this.vacations[index].status = 'approved';
      }
    },
    rejectVacation(index) {
      if (confirm('确定要拒绝这条假期申请吗？')) {
        this.vacations[index].status = 'rejected';
      }
    },
    viewVacation(index) {
      this.editingIndex = index;
      this.showAddVacationModal = true;
    },
    deleteVacation(index) {
      if (confirm('确定要删除这条假期记录吗？')) {
        this.vacations.splice(index, 1);
      }
    },
    saveVacation() {
      this.showAddVacationModal = false;
      this.editingIndex = null;
    }
  }
}
</script>

<style scoped>
/* 继承基础样式并添加差异化样式 */
.page-container {
  padding: 24px;
  max-width: 1400px;
  margin: 0 auto;
  background: #f8fafc;
  min-height: 100vh;
}

.page-header {
  margin-bottom: 24px;
  display: flex;
  align-items: center;
  gap: 20px;
}

.header-content h2 {
  margin: 0 0 8px 0;
  color: #1e293b;
  font-size: 24px;
  font-weight: 600;
}

.header-content p {
  margin: 0;
  color: #64748b;
  font-size: 14px;
}

.back-button {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 9px 16px;
  background: #3b82f6;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.3s ease;
  font-weight: 500;
}

.back-button:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.back-button:active {
  transform: translateY(0);
}

.card {
  background: white;
  border-radius: 10px;
  box-shadow: 0 3px 10px rgba(0, 0, 0, 0.08);
  margin-bottom: 24px;
  overflow: hidden;
  transition: all 0.3s ease;
}

.card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
}

.card-header {
  padding: 16px 24px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.card-header h3 {
  margin: 0;
  color: #1e293b;
  font-size: 18px;
  font-weight: 600;
}

.card-body {
  padding: 24px;
}

/* 过滤区样式 */
.filters-card {
  padding: 16px 24px;
}

.filters-container {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  align-items: center;
}

.filter-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filter-group label {
  color: #334155;
  font-weight: 500;
  font-size: 14px;
}

.filter-group select,
.form-control {
  padding: 9px 12px;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  background: white;
  font-size: 14px;
  transition: all 0.2s ease;
}

.filter-group select:focus,
.form-control:focus {
  outline: none;
  border-color: #3b82f6;
  box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.1);
}

.filter-actions {
  margin-left: auto;
}

/* 统计项样式 */
.header-stats {
  display: flex;
  gap: 24px;
}

.stat-item {
  display: flex;
  align-items: center;
  gap: 6px;
}

.stat-label {
  color: #64748b;
  font-size: 14px;
}

.stat-value {
  font-weight: 600;
  color: #1e293b;
  font-size: 15px;
}

/* 表格样式 */
.table-responsive {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  min-width: 900px;
}

.data-table th,
.data-table td {
  padding: 14px 16px;
  text-align: left;
  border-bottom: 1px solid #f1f5f9;
  font-size: 14px;
}

.data-table th {
  background-color: #f8fafc;
  font-weight: 600;
  color: #334155;
  position: sticky;
  top: 0;
  z-index: 10;
}

.table-row:hover {
  background-color: #f8fafc;
  transition: background-color 0.2s;
}

/* 优先级和状态标签 */
.priority, .status {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.priority.high {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.priority.medium {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.priority.low {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.status.pending {
  background: rgba(148, 163, 184, 0.1);
  color: #64748b;
}

.status.inProgress {
  background: rgba(59, 130, 246, 0.1);
  color: #2563eb;
}

.status.completed {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.status.delayed {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

/* 进度条样式 */
.progress-bar {
  height: 8px;
  background-color: #f1f5f9;
  border-radius: 4px;
  overflow: hidden;
  position: relative;
}

.progress-fill {
  height: 100%;
  background-color: #3b82f6;
  transition: width 0.3s ease;
}

.progress-text {
  position: absolute;
  right: 5px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  color: #334155;
  font-weight: 500;
}

.text-danger {
  color: #dc2626;
  font-weight: 500;
}

/* 按钮样式 */
.btn-primary {
  background: #3b82f6;
  color: white;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 6px;
  transition: all 0.3s ease;
  font-weight: 500;
}

.btn-primary:hover {
  background: #2563eb;
  transform: translateY(-2px);
  box-shadow: 0 4px 12px rgba(59, 130, 246, 0.25);
}

.btn-primary:active {
  transform: scale(0.98);
}

.btn-action {
  background: #f1f5f9;
  border: none;
  padding: 6px 12px;
  border-radius: 4px;
  cursor: pointer;
  margin-right: 6px;
  font-size: 13px;
  color: #334155;
  transition: all 0.2s ease;
}

.btn-action:hover {
  background: #e2e8f0;
  transform: translateY(-1px);
}

.btn-action:active {
  transform: scale(0.96);
}

.btn-danger {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.btn-danger:hover {
  background: rgba(239, 68, 68, 0.2);
}

.action-buttons {
  display: flex;
  gap: 6px;
}

/* 空状态样式 */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: #64748b;
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 16px;
  opacity: 0.7;
}

/* 弹窗样式 */
.modal-backdrop {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  animation: fadeIn 0.3s;
}

.modal {
  background: white;
  border-radius: 10px;
  width: 90%;
  max-width: 600px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.3s;
}

.modal-header {
  padding: 16px 24px;
  border-bottom: 1px solid #f1f5f9;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-header h3 {
  font-size: 18px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  color: #64748b;
  transition: color 0.2s, transform 0.2s;
}

.modal-close:hover {
  color: #dc2626;
  transform: rotate(90deg);
}

.modal-body {
  padding: 24px;
}

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  margin-bottom: 6px;
  color: #334155;
  font-weight: 500;
  font-size: 14px;
}

.form-row {
  display: flex;
  gap: 16px;
}

.form-row .form-group {
  flex: 1;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid #f1f5f9;
  display: flex;
  justify-content: flex-end;
  gap: 12px;
}

.btn-secondary {
  background: #f1f5f9;
  color: #334155;
  border: none;
  padding: 9px 18px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.2s ease;
  font-weight: 500;
}

.btn-secondary:hover {
  background: #e2e8f0;
  transform: translateY(-2px);
}

.btn-secondary:active {
  transform: scale(0.98);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

@keyframes slideIn {
  from { transform: scale(0.95); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

/* 假期类型标签 */
.vacation-type {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.vacation-type.annual {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.vacation-type.sick {
  background: rgba(59, 130, 246, 0.1);
  color: #2563eb;
}

.vacation-type.personal {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.vacation-type.marriage {
  background: rgba(139, 92, 246, 0.1);
  color: #7c3aed;
}

.vacation-type.maternity {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

/* 状态标签 */
.status {
  padding: 4px 10px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.status.pending {
  background: rgba(245, 158, 11, 0.1);
  color: #d97706;
}

.status.approved {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.status.rejected {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

/* 理由单元格 */
.reason-cell {
  max-width: 220px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* 审批按钮 */
.btn-approve {
  background: rgba(34, 197, 94, 0.1);
  color: #16a34a;
}

.btn-approve:hover {
  background: rgba(34, 197, 94, 0.2);
}

.btn-reject {
  background: rgba(239, 68, 68, 0.1);
  color: #dc2626;
}

.btn-reject:hover {
  background: rgba(239, 68, 68, 0.2);
}

.pending-count {
  color: #d97706;
}
</style>